package day05.JavaCodeHomework;
import java.util.Arrays;
import java.util.Random;
public class StanardPractice {
    public static void main(String[] args) {
        //Q1. MultiTable九九乘法表 (要求: 输出九九乘法表)
            //第一遍:
                /*
                for (int Line1 = 1; Line1 <= 9; Line1++) {
                    for (int Row1 = 1; Row1 <= 9; Row1++) {
                        System.out.print(Row1 + "*" + Line1 + "=" + Row1 * Line1 + "\t");
                    }
                    System.out.println();
                }
                 */

            //第二遍:
            /*
            for (int Line2 = 1; Line2 <= 9; Line2++) {
                for (int Row2 = 1; Row2 <= 9; Row2++) {
                    System.out.print(Row2 + "*" + Line2 + "=" + Line2 * Row2 + "\t");
                }
                System.out.println();
            }
             */

            //第三遍:
            /*
            for (int Line3 = 1; Line3 <= 9; Line3++) {
                for (int Row3 = 1; Row3 <= 9; Row3++) {
                    System.out.print(Row3 + "*" + Line3 + "=" + Row3 * Line3 + "\t");
                }
                System.out.println();
            }
             */

            //第四遍:
            /*
            for (int Line4 = 1; Line4 <= 9; Line4++) {
                for (int Row4 = 1; Row4 <= 9; Row4++) {
                    System.out.print(Row4 + "*" + Line4 + "=" + (Row4 * Line4) + "\t");
                }
                System.out.println();
            }
             */

            //第五遍:
            /*
            for (int Line5 = 1; Line5 <= 9; Line5++) {
                for (int Row5 = 1; Row5 <= 9; Row5++) {
                    System.out.print(Row5 + "*" + Line5 + "=" + (Row5 * Line5) + "\t");
                }
                System.out.println();
            }
             */

        //Q2.  数组小代码练习：声明、初始化、访问、遍历、复制
            //第一遍:
                /*
                int[] arr1 = new int[10];

                int[] arr2 = {2, 4, 8, 6};

                System.out.println(arr2.length);
                arr2[0] = 200;
                arr2[1] = 400;
                arr2[2] = 800;
                arr2[3] = 600;
                System.out.println(arr2[arr2.length - 1]);

                for (int i = 0; i < arr2.length; i++) {
                    System.out.println(arr2[i]);
                }

                arr2 = Arrays.copyOf(arr2, arr2.length + 1);
                 */

            //第二遍:
                /*
                int[] arr3 = new int[20];

                int[] arr4 = new int[]{2, 5, 6, 8, 10};

                System.out.println(arr4.length);
                arr4[0] = 200;
                arr4[1] = 500;
                arr4[2] = 600;
                arr4[3] = 600;
                arr4[4] = 800;
                //arr4[5] = 10000;
                //arr4[6] = 15000;
                System.out.println(arr4[arr4.length - 1]);

                for (int i = 0; i < arr4.length; i++) {
                    arr4[i] = (int)(Math.random() * 100);
                    System.out.println(arr4[i]);
                }

                int[] arr5 = new int[]{2, 4, 6, 8, 10};
                arr5 = Arrays.copyOf(arr5, arr5.length + 1);
                for (int i = 0; i < arr5.length; i++) {
                    System.out.println(arr5[i]);
                }
                */

            //第三遍:
                /*
                int[] arr1 = new int[10];
                int[] arr2 = new int[20];

                int[] arr3 = new int[]{4, 5, 6, 7, 8};
                int[] arr4 = {6, 7, 8, 9, 10};
                int[] arr5 = new int[]{4, 3, 2, 1, 0};

                int[] arr6 = new int[]{6, 2, 3, 5, 8};
                System.out.println(arr6.length);
                arr6[0] = 1;
                arr6[1] = 0;
                arr6[2] = 2;
                arr6[3] = 3;
                arr6[4] = 5;
                //arr6[5] = 8;    //越界
                System.out.println(arr6[arr6.length - 1]);

                int[] arr7 = new int[10];
                Random rand = new Random();
                for (int i = 0; i < arr7.length; i++) {
                    arr7[i] = rand.nextInt(100);
                    System.out.println(arr7[i]);
                }

                int[] arr8 = new int[] {10, 20, 30, 40, 50};
                arr8 = Arrays.copyOf(arr8, arr8.length + 1);
                for (int i = 0; i < arr8.length; i++) {
                    System.out.println(arr8[i]);
                }
                 */

        //Q3. MaxOfArray求数组元素最大值并放在最后一个元素的下一个位置
            //第一遍:
                /*
                int[] arr1 = new int[10];
                Random rand1 = new Random();
                for (int i = 0; i < arr1.length; i++) {
                    arr1[i] = rand1.nextInt(100);
                }

                int max1 = arr1[0];
                for (int i = 0; i < arr1.length; i++) {
                    if (arr1[i] > max1) {
                        max1 = arr1[i];
                    }
                }
                System.out.println(max1);

                System.out.println();

                arr1 = Arrays.copyOf(arr1, arr1.length + 1);
                arr1[arr1.length - 1] = max1;
                for (int i = 0; i < arr1.length; i++) {
                    System.out.println(arr1[i]);
                }
                 */

            //第二遍:
                /*
                int[] arr2 = new int[10];
                Random rand2 = new Random();
                for (int i = 0; i < arr2.length; i++) {
                    arr2[i] = rand2.nextInt(100);
                    System.out.println(arr2[i]);
                }

                System.out.println();

                int max2 = arr2[0];
                for (int i = 0; i < arr2.length; i++) {
                    if (arr2[i] > max2) {
                        max2 = arr2[i];
                    }
                }
                System.out.println(max2);

                System.out.println();

                arr2 = Arrays.copyOf(arr2, arr2.length + 1);
                arr2[arr2.length - 1] = max2;
                for (int i = 0; i < arr2.length; i++) {
                    System.out.println(arr2[i]);
                }
                 */

        //Q4.  对数组进行升序排列，并输出排序后的结果
            //第一遍:
                /*
                Random rand1 = new Random();
                int[] arr1 = new int[10];
                for (int i = 0; i < arr1.length; i++) {
                    arr1[i] = rand1.nextInt(100);
                    System.out.println(arr1[i]);
                }

                System.out.println();

                System.out.println("正排序为:");
                Arrays.sort(arr1);
                for (int i = 0; i < arr1.length; i++) {
                    System.out.println(arr1[i]);
                }

                System.out.println();

                System.out.println("倒排序为:");
                for (int i = arr1.length - 1; i >= 0; i--) {
                    System.out.println(arr1[i]);
                }
                System.out.println(arr1[0]);
                 */

            //第二遍:
                /*
                Random rand2 = new Random();
                int[] arr2 = new int[10];
                for (int i = 0; i < arr2.length; i++) {
                    arr2[i] = rand2.nextInt(100);
                    System.out.println(arr2[i]);
                }

                System.out.println();

                System.out.println("正序为:");
                Arrays.sort(arr2);
                for (int i = 0; i < arr2.length; i++) {
                    System.out.println(arr2[i]);
                }

                System.out.println();

                System.out.println("倒叙为:");
                for (int i = arr2.length - 1; i >= 0; i--) {
                    System.out.println(arr2[i]);
                }
                System.out.println("第一个元素为:" + arr2[0]);
                 */

                //第三遍:
                /*
                Random rand3 = new Random();
                int[] arr3 = new int[10];
                for (int i = 0; i < arr3.length; i++) {
                    arr3[i] = rand3.nextInt(100);
                    System.out.println(arr3[i]);
                }

                System.out.println();

                System.out.println("正序为:");
                Arrays.sort(arr3);
                for (int i = 0; i < arr3.length; i++) {
                    System.out.println(arr3[i]);
                }

                System.out.println();

                System.out.println("倒叙为:");
                for (int i = arr3.length - 1; i >= 0; i--) {
                    System.out.println(arr3[i]);
                }
                System.out.println("第一个元素为:" + arr3[0]);
                 */
    }
}
